import os
import time

import page
from base.base import Base


class PageOrderEvaluate(Base):
    # 点击评论
    def page_click_comment(self):
        self.base_click_element(page.get_comment_elements()['comment'])

    # 点击星级满意度
    def page_click_rating_star(self):
        self.base_click_element(page.get_comment_elements()['rating_start'])

    # 输入评语（填写评论内容）
    def page_input_comment_content(self, comment):
        self.base_in_element_input(page.product_comment_content, comment)

    # 选择本地中的一张图片
    def page_upload_comment_image(self, image):
        self.base_click_element(page.product_comment_file_submit)
        self.base_switch_to_iframe(page.product_comment_file_iframe)
        image_path = os.path.abspath(image)
        self.base_upload_hidden_file(page.product_comment_image, image_path)
        self.base_click_element(page.product_comment_image_upload)
        time.sleep(1)
        self.base_switch_to_default_content()
        self.base_click_element(page.product_comment_image_submit)

    # 点击匿名
    def page_click_anonymous_comment(self):
        self.base_click_element(page.product_anonymous_comment)

    # 点击提交
    def page_click_submit_comment(self):
        self.base_click_element(page.product_submit_comment)

    # 切换窗口
    def page_switch_to_window(self, expect_title):
        self.base_switch_to_window(expect_title)

    def page_comment(self, comment, image):
        self.page_click_rating_star()
        self.page_input_comment_content(comment)
        self.page_upload_comment_image(image)
        self.page_click_anonymous_comment()
        self.page_click_submit_comment()